package com.zxl.live.screen.model.bean;

import com.liulishuo.filedownloader.FileDownloader;
import com.liulishuo.filedownloader.model.FileDownloadStatus;
import com.liulishuo.filedownloader.util.FileDownloadUtils;

import java.io.File;

/**
 * Created by Administrator on 2017/8/3.
 */
public class DownloadBean {

    public static final String TYPE_WALLPAPER = "image";

    public static final String TYPE_RINGTONE = "ringtone";

    public static final String TYPE_CALL_FLASH = "callFlash";

    public static final String TYPE_LOCK = "lock";

    public static final String TYPE_SUI = "sui";

    public static final String TYPE_GIF = "sui";

    private int id;

    public String name;

    public String url;

    public String path;

    public String mimeType;

    public long createTimer;

    public DownloadBean() {
    }

    private DownloadBean(String url, String path, String mimeType) {
        this.url = url;
        this.mimeType = mimeType;
        name = new File(url).getName();
        this.path = path;
        id = FileDownloadUtils.generateId(url, path);
        createTimer = System.currentTimeMillis();
    }

    public static DownloadBean createWallpaperBean(String url, String path) {
        return new DownloadBean(url, path, TYPE_WALLPAPER);
    }

    public static DownloadBean createRingtoneBean(String url, String path) {
        return new DownloadBean(url, path, TYPE_RINGTONE);
    }

    public static DownloadBean createCallFlashBean(String url, String path) {
        return new DownloadBean(url, path, TYPE_CALL_FLASH);
    }

    public static DownloadBean createGifBean(String url, String path) {
        return new DownloadBean(url, path, TYPE_GIF);
    }

    public static DownloadBean createLockThemeBean(String url, String path) {
        return new DownloadBean(url, path, TYPE_LOCK);
    }

    public static DownloadBean createSuiBean(String url, String path) {
        return new DownloadBean(url, path, TYPE_SUI);
    }

    public long getSoFar() {
        return FileDownloader.getImpl().getSoFar(getId());
    }

    public long getTotal() {
        return  FileDownloader.getImpl().getTotal(getId());
    }

    public byte getStatus() {
        try {
            return FileDownloader.getImpl().getStatus(getId(), path);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return FileDownloadStatus.INVALID_STATUS;
    }

    public int getId() {
        if (id == 0) {
            id = FileDownloadUtils.generateId(url, path);
        }
        return id;
    }


}
